package com.cdtu.store.item.controller;

import com.cdtu.store.common.utils.PageUtils;
import com.cdtu.store.common.utils.R;
import com.cdtu.store.common.entity.SpecGroupEntity;
import com.cdtu.store.item.service.SpecGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;




/**
 * 规格参数的分组表，每个商品分类下有多个规格参数组
 *
 * @author dongyuhao
 * @email a1059444570@qq.com
 * @date 2020-06-22 19:53:26
 */
@RestController
@RequestMapping("specgroup")
public class SpecGroupController {
    @Autowired
    private SpecGroupService specGroupService;

    /**
     * 列表
     */
    @RequestMapping("/list/{cid}")
    public R list(@RequestParam Map<String, Object> params,@PathVariable("cid") Long cid){
        //PageUtils page = specGroupService.queryPage(params);
        PageUtils page = specGroupService.queryPage(params, cid);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SpecGroupEntity specGroup = specGroupService.getById(id);

        return R.ok().put("specGroup", specGroup);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody SpecGroupEntity specGroup){
		specGroupService.save(specGroup);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody SpecGroupEntity specGroup){
		specGroupService.updateDetail(specGroup);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		specGroupService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
